import com.spheres.quiniela.domain.Team
import com.spheres.quiniela.domain.Group
import com.spheres.quiniela.domain.FixtureNumber
import com.spheres.quiniela.domain.FixtureNumberType
import com.spheres.quiniela.domain.UserRole
import com.spheres.quiniela.domain.User
import com.spheres.quiniela.domain.Role

class BootStrap {

  def springSecurityService

  def init = { servletContext ->
    def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
    def userRole = new Role(authority: 'ROLE_USER').save(flush: true)

    String password = springSecurityService.encodePassword('sa')
    def adminUser = new User(username: 'admin', enabled: true, password: password)
    adminUser.save(flush: true)

    UserRole.create adminUser, adminRole, true

    def user = new User(username: 'demo', enabled: true, password: springSecurityService.encodePassword('demo'))
    user.save(flush: true)

    UserRole.create user, userRole, true

    new FixtureNumber(number: 1, type: FixtureNumberType.REGULAR).save(flush: true)
    new FixtureNumber(number: 2, type: FixtureNumberType.REGULAR).save(flush: true)
    new FixtureNumber(number: 3, type: FixtureNumberType.REGULAR).save(flush: true)
    new FixtureNumber(number: 4, type: FixtureNumberType.SECONDROUND).save(flush: true)
    new FixtureNumber(number: 5, type: FixtureNumberType.QUARTERFINALS).save(flush: true)
    new FixtureNumber(number: 6, type: FixtureNumberType.SEMIFINALS).save(flush: true)
    new FixtureNumber(number: 7, type: FixtureNumberType.THIRDPLACE).save(flush: true)
    new FixtureNumber(number: 8, type: FixtureNumberType.FINAL).save(flush: true)
    def group = new Group(name: "A")
    group.save(flush: true)
    def team = new Team(name: "Mexico", group: group)
    team.save(flush: true)
    new Team(name: "Sudafrica", group: group).save(flush: true)
    new Team(name: "Francia", group: group).save(flush: true)
    new Team(name: "Uruguay", group: group).save(flush: true)
  }
  def destroy = {
  }
} 